'use strict'

define(['jquery', 'bootstrap', 'select2','shiftform', 'validate', 'validate.en','uploader', 'plupload', 'qiniu'], function($) {
  
  return {
        
    init: function() {
    	this.initEditBatch();
    	this.initCreateCourseware();
    	this.initEditCourseware();
        this.initDeleteCourseware();
    },
    
    initEditBatch: function(){
        var that = this;
        
        $(document).on("shown.bs.modal","#info-edit", function(e) {
        	
            var $form = $(e.currentTarget).find("form");
            
            $form.bt_validate();
          
            $form.shiftform({
              beforeSubmit : function(el) {
                $('form').trigger("validate.ajax.submit");
                return $.bt_validate.result[$.bt_validate.form_id]
              }
            });
        })
             
    },
    
    initCreateCourseware: function(){
        var that = this;
        
        $(document).on("shown.bs.modal","#create", function(e) {
        	
            var $form = $(e.currentTarget).find("form");
            
            $form.bt_validate();
          
            $form.shiftform({
              beforeSubmit : function(el) {
                $('form').trigger("validate.ajax.submit");
                return $.bt_validate.result[$.bt_validate.form_id]
              }
            });
        })
             
    },
    
    initEditCourseware: function(){
        var that = this;
        
        $(document).on("shown.bs.modal","#edit, #daily-edit", function(e) {
        	
            var $form = $(e.currentTarget).find("form");
            
            $form.bt_validate();
          
            $form.shiftform({
              beforeSubmit : function(el) {
                $('form').trigger("validate.ajax.submit");
                return $.bt_validate.result[$.bt_validate.form_id]
              }
            });
        })
             
    },
    
    initDeleteCourseware: function() {
        $(document).on('shown.bs.modal', '#delete', function(e){

        $(e.currentTarget).find("form").shiftform()
      })
    }
    
   }
})
